import typeOfUtils from '../utils/type-of-utils'
import {ComponentOptions} from "vue/types/options";

const tableSelectMixin: ComponentOptions<any> = {
  data() {
    return {
      tableSelect: []
    }
  },
  computed: {
    tableHasSelect() {
      return !typeOfUtils.isEmpty(this.tableSelect)
    },
    tableOnlySelectOne() {
      if (this.tableHasSelect) {
        if (this.tableSelect.length === 1) {
          return true
        }
      }
      return false
    },
    tableOnlySelectOneData() {
      if (this.tableOnlySelectOne) {
        return this.tableSelect[0]
      }
      return {}
    }
  },
  methods: {
    selectionChange(rows) {
      this.tableSelect = rows
    },
  }
}

export default tableSelectMixin

/**
 *     <DynamicTable
 *       @selection-change="selectionChange"
 *     >
 */
